<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">

<link rel="stylesheet" type="text/css" href="log.css" media="all"/>
<link rel="stylesheet" type="text/css" href="common.css" media="all"/>
<link rel="stylesheet" type="text/css" href="print.css" media="print"/>
<script type="text/javascript" src="log.js"></script>
<script type="text/javascript" src="lib/jquery.min.js"></script>
<script type="text/javascript" src="lib/jquery.tmpl.min.js"></script>
<!-- OUTPUT JS --><script type="text/javascript" src="testdata/data.js"></script>
<script type="text/javascript" src="lib/jsxcompressor.js"></script>
<script type="text/javascript" src="model.js"></script>
<script type="text/javascript" src="util.js"></script>
<script type="text/javascript" src="testdata.js"></script>
<script type="text/javascript" src="stats.js"></script>

<title></title>
</head>
<body>
<div id="javascript_disabled" class="error_box">
      <h1>Error when opening log.</h1>
      <ul>
          <li>Check that JavaScript is enabled in your browser.</li>
          <li>Minimum browser requirements: IE8, Firefox +3.5, Chrome xx, Safari zz, Opera yy.</li>
          <li>Check JavaScript error log if there are errors.</li>
      </ul>
</div>
<div id="javascript_enabled" style="visibility: hidden;">
    <div class="header" id="header_div">
    </div>
      <h2>Test Statistics</h2>
      <table class="statistics" id="total_stats">
        <tr>
          <th class="col_stat_name">Total Statistics</th>
          <th class="col_stat">Total</th>
          <th class="col_stat">Pass</th>
          <th class="col_stat">Fail</th>
          <th class="col_graph">Graph</th>
        </tr>
      </table>
      <table class="statistics" id="tag_stats">
        <tr>
          <th class="col_stat_name">Statistics by Tag</th>
          <th class="col_stat">Total</th>
          <th class="col_stat">Pass</th>
          <th class="col_stat">Fail</th>
          <th class="col_graph">Graph</th>
        </tr>
      </table>
      <table class="statistics" id="suite_stats">
        <tr>
          <th class="col_stat_name">Statistics by Suite</th>
          <th class="col_stat">Total</th>
          <th class="col_stat">Pass</th>
          <th class="col_stat">Fail</th>
          <th class="col_graph">Graph</th>
        </tr>
      </table>
</div>
<script type="text/javascript">
$(document).ready(function(){
    removeJavaScriptDisabledWarning();
    var topsuite = window.testdata.suite();
    window.templates = initTemplates();
    setDocumentTitle(topsuite.name, window.settings.title);
    addHeader();
    addStatistics();
    addErrors();
    addTestExecutionLog(topsuite);
    if (window.location.hash) {
        makeElementVisible(window.location.hash.substring(1));
        window.location.hash = window.location.hash.substring(1);
    } else {
        expandFailed(topsuite);
    }
});

function removeJavaScriptDisabledWarning() {
    $('#javascript_disabled').remove();
    $('#javascript_enabled').css('visibility', 'visible');
}

// TODO: This is duplicated in report.html
function addHeader() {
    var generatedAgoMillis = window.testdata.generated().getTime();
    var header = $.tmpl(window.templates.header, {
        title: document.title,
        generated: window.output.generatedTimestamp,
        generatedAgo: util.createGeneratedAgoString(generatedAgoMillis)
    });
    header.appendTo($('#header_div'));
}

function addErrors() {
    var errors = window.testdata.errors();
    if (errors.length) {
        $.tmpl(window.templates.errorHeader).appendTo($('body'));
        $.tmpl(window.templates.error, errors).appendTo($('#error_table'));
    }
}

function makeElementVisible(element) {
    var uuids = [];
    if (element.indexOf("suite_")==0) {
        element = element.substring("suite_".length);
        uuids = window.testdata.pathToSuite(unescape(element));
    }
    if (element.indexOf("test_")==0) {
        element = element.substring("test_".length);
        uuids = window.testdata.pathToTest(unescape(element));
    }
    if (element.indexOf("keyword_")==0) {
        element = element.substring("keyword_".length);
        uuids = window.testdata.pathToKeyword(unescape(element));
    }
    for (var i in uuids) {
        $("#"+uuids[i]+"_unfoldlink").click();
    }
    if (uuids && uuids.length > 0) {
        expandFailed(window.testdata.find(uuids[uuids.length-1]));
    }
}

function addTestExecutionLog(main) {
    $('<h2>Test Execution Log</h2>').appendTo($('body'));
    var root = $.tmpl(window.templates.suite, main);
    root.appendTo($('body'));
    if (main.status == "pass") {
        $("#"+main.id+"_unfoldlink").click();
    }
}

// TODO: Duplicated in report.html
function setDocumentTitle(suiteName, givenTitle) {
    document.title = givenTitle ? givenTitle : suiteName + " Test Log";
}

function initTemplates() {
    return {
        header: $('#header_template').template(),
        totalStatRow: $('#total_statistics_row').template(),
        tagStatRow: $('#tag_statistics_row').template(),
        suiteStatRow: $('#suite_statistics_row').template(),
        noTagsRow: $('#no_tags_row').template(),
        errorHeader: $('#error_header_template').template(),
        error: $('#error_template').template(),
        suite: $('#suite_template').template(),
        test: $('#test_template').template(),
        keyword: $('#keyword_template').template(),
        message: $('#message_template').template(),
    };
};
</script>

<!-- TODO: This is duplicated in report.html -->
<script type="text/html" id="header_template">
  <div id="generated">
    <span>Generated<br />${generated}</span><br />
    <span id="generated_ago">${generatedAgo} ago</span>
  </div>
  <h1>${title}</h1>
</script>

<script type="text/html" id="total_statistics_row">
  <tr>
    <td class="col_stat_name">
      <div class="stat_name">
        <span title="${doc}">${label}</span>
      </div>
    </td>
    {{tmpl($data) '#stat_columns'}}
  </tr>
</script>

<script type="text/html" id="tag_statistics_row">
  <tr>
    <td class="col_stat_name">
      <div class="stat_name">
        <span title="${doc}">${label}</span>
        ${shownInfo}
      </div>
      <div class="tag_links">
        {{each links}}
        <span>[<a href="${$value.url}" title="${$value.url}">${$value.title}</a>]</span>
        {{/each}}
      </div>
    </td>
    {{tmpl($data) '#stat_columns'}}
  </tr>
</script>

<script type="text/html" id="suite_statistics_row">
  <tr>
    <td class="col_stat_name">
      <div class="stat_name">
        <a onclick="makeElementVisible('suite_${label}')" href="#suite_${label}" title="${label}"><span class="parent_name">${parentName}</span>${name}</a>
      </div>
    </td>
    {{tmpl($data) '#stat_columns'}}
  </tr>
</script>

<script type="text/html" id="stat_columns">
  <td class="col_stat">${total}</td>
  <td class="col_stat">${pass}</td>
  <td class="col_stat">${fail}</td>
  <td class="col_graph">
    <div class="graph">
      <b class="pass_bar" style="width: ${passWidth}%;" title="${passPercent}%"></b>
      <b class="fail_bar" style="width: ${failWidth}%;" title="${failPercent}%"></b>
    </div>
  </td>
</script>

<script type="text/html" id="no_tags_row">
  <tr>
    <td class="col_stat_name">No Tags</td>
    <td class="col_stat"></td>
    <td class="col_stat"></td>
    <td class="col_stat"></td>
    <td class="col_graph">
      <div class="graph">
        <b class="no_tags_bar" style="width: 100%;"></b>
      </div>
    </td>
  </tr>
</script>

<script type="text/html" id="error_header_template">
  <h2>Test Execution Errors</h2>
  <table class="errors" id="error_table"></table>
</script>

<script type="text/html" id="error_template">
  <tr>
    <td class="time">
      {{if link}}
      <a onclick="makeElementVisible('${link}')"
         href="#${link}" title="Link to details.">${date}</a>
      {{else}}
      ${date}
      {{/if}}
    </td>
    <td class="${level} level">${levelText}</td>
    <td class="msg">{{html text}}</td>
  </tr>
</script>

<script type="text/html" id="suite_template">
  <table class="suite" id="${id}">
    <tr>
      <td>
        <a class="expand"
           href="javascript:expandAllChildren('${id}')">Expand All</a>
        <div class="foldingbutton" id="${id}_unfoldlink"
             onclick="openSuite('${id}');"
             style="display: block;">+</div>
        <div class="foldingbutton" id="${id}_foldlink"
             onclick="closeElement('${id}');"
             style="display: none;">-</div>
        <span class="${status}">TEST&nbsp;SUITE:</span>
        <a class="name" name="suite_${fullname}" title="${name}">${name}</a>
      </td>
    </tr>
    <tr>
      <td class="suite_children">
        <div class="indent" id="${id}_children" style="display: none;">
          <table class="metadata" id="${id}_metadata">
            <tr><th>Full Name:</th><td>${fullname}</td></tr>
            {{if documentation}}
            <tr><th>Documentation:</th><td>{{html documentation}}</td></tr>
            {{/if}}
            {{each metadata}}
            <tr><th>${$index}:</th><td>{{html $value}}</td></tr>
            {{/each}}
            <!-- TODO: Link (href) to source should be relative -->
            <tr><th>Source:</th><td><a href="${source}">${source}</a></td></tr>
            <tr><th>Start / End / Elapsed:</th><td>${times.startTime}  /  ${times.endTime}  /  ${times.elapsedTime}</td></tr>
            <tr><th>Status:</th><td>{{tmpl($data) '#stats_message_partial_template'}}</td></tr>
            {{if message}}
            <tr><th>Message:</th><td>${message}</td></tr>
            {{/if}}
          </table>
        </div>
      </td>
    </tr>
  </table>
</script>

<script type="text/html" id="stats_message_partial_template">
${critical} critical test, ${criticalPassed} passed, <span class="${criticalFailureClass}">${criticalFailed} failed</span><br />${total} test total, ${totalPassed} passed, <span class="${totalFailureClass}">${totalFailed} failed</span>
</script>

<script type="text/html" id="test_template">
  <table class="test" id="${id}">
    <tr>
      <td>
        <a class="expand"
           href="javascript:expandAllChildren('${id}')">Expand All</a>
        <div class="foldingbutton"
             id="${id}_unfoldlink"
             onclick="openTest('${id}');"
             style="display: block;">+</div>
        <div class="foldingbutton"
             id="${id}_foldlink"
             onclick="closeElement('${id}');"
             style="display: none;">-</div>
        <span class="${status}">TEST&nbsp;CASE: </span>
        <a class="name" name="test_${fullname}"
           title="${fullname}">${name}</a>
      </td>
    </tr>
    <tr>
      <td>
        <div class="indent" id="${id}_children" style="display: none;">
          <table class="metadata" id="${id}_metadata">
            <tr><th>Full Name:</th><td>${fullname}</td></tr>
            {{if documentation}}
            <tr><th>Documentation:</th><td>{{html documentation}}</td></tr>
            {{/if}}
            {{if tags.length}}
            <tr><th>Tags:</th><td>${tags.join(', ')}</td></tr>
            {{/if}}
            {{if timeout}}
            <tr><th>Timeout:</th><td>${timeout}</td></tr>
            {{/if}}
            <tr><th>Start / End / Elapsed:</th><td>${times.startTime}  /  ${times.endTime}  /  ${times.elapsedTime}</td></tr>
            <tr><th>Status:</th><td class="${status}">${statusText}</td></tr>
            {{if message}}
            <tr><th>Message:</th><td>${message}</td></tr>
            {{/if}}
          </table>
        </div>
      </td>
    </tr>
  </table>
</script>

<script type="text/html" id="keyword_template">
  <table class="keyword" id="${id}">
    <tr>
      <td>
        <div class="foldingbutton"
             id="${id}_foldlink"
             onclick="closeElement('${id}');"
             style="display: none;">-</div>
        <div class="foldingbutton"
             id="${id}_unfoldlink"
             onclick="openKeyword('${id}');"
             style="display: block;">+</div>
        <span class="${status}">${type}: </span>
        <a class="name" name="keyword_${path}" title="${name}">${name}</a>
        <span class="arg">${arguments}</span>
      </td>
    </tr>
    <tr>
      <td>
        <div class="indent" id="${id}_children" style="display: none;">
          <table class="metadata" id="${id}_metadata">
            {{if documentation}}
            <tr><th>Documentation:</th><td>{{html documentation}}</td></tr>
            {{/if}}
            <tr><th>Start / End / Elapsed:</th><td>${times.startTime}  /  ${times.endTime}  /  ${times.elapsedTime}</td></tr>
          </table>
        </div>
      </td>
    </tr>
  </table>
</script>

<script type="text/html" id="message_template">
  <table class="messages">
    <tr>
      <td class="time">${shortTime()}</td>
      <td class="${level} level">${levelText}</td>
      <td class="msg">{{html text}}</td>
    </tr>
  </table>
</script>

</body>
</html>
